
  
  <body>
    <div class="x-body">
        <form class="layui-form" id="userUpate">
          <input type="hidden" id="id" name="id"  value="{{$user.id}}"/>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>登录名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="username" required="" lay-verify="required"
                  autocomplete="off" value="{{$user.username}}" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您唯一的登入名
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label"><span class="x-red">*</span>角色</label>
              <div class="layui-input-block">
              {{foreach $roles:$role}}
                <input type="radio" name="role_id" lay-skin="primary" title="{{$role.name}}" {{if $user['role_id']== $role['id']}} checked=""{{endif}} value="{{$role.id}}">
               {{endforeach}} 
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_pass" class="layui-form-label">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="L_pass" name="pwd" required="" lay-verify="pwd"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  6到16个字符
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
                  <span class="x-red">*</span>确认密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="L_repass"  required="" lay-verify="repass"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  增加
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          var layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            },
            pwd: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });

          //监听提交
          form.on('submit(add)', function(){
            
            var form = $('#userUpate').serialize();
            // console.log(form);
            //发异步，把数据提交给php
            $.post('/admin/admin/edit.html',form,function(result){
                var res = JSON.parse(result);
                if (res.status == 0) {
                    // console.log(res)
                    layer.alert(res.msg, {icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        // 刷新父iframe
                        window.parent.location.reload();
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                }
                if (res.status == 1){
                    layer.alert(res.msg, {icon: 5})
                }
            })
            return false;
          });
          
          
        });
    </script>

  </body>

</html>